<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'MyJsp.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<jsp:include page="/scripts/common/index.html"></jsp:include>
<jsp:include page="/scripts/dhtmlx/index.html"></jsp:include>
<jsp:include page="/scripts/jquery/index.html"></jsp:include>
<jsp:include page="/scripts/bootstrap/index.html"></jsp:include>
<link rel="stylesheet" href="${basepath }style/default.css">
</head>
<script type="text/javascript">
	var temp = false;
	function init(){
		
	}
	function save() {
		$('#MyForm').bootstrapValidator('validate');
		if (temp) {
			$.ajax({
				type : 'POST' ,
				url : 'page/system/staff/Staff/doAdd' ,
				data : $('#MyForm').serializeArray() ,
				dataType : "json" ,
				async : true ,
				cache : false ,
				jsonpCallback : "null" ,
				success : function(response, status, statusText) {
					if (response.status) {
						 if (response.content == "有重复的员工工号，请重新输入！") {
							SN.alert.info("有重复的员工工号，请重新输入！");
						}else if(response.content == "有重复的用户账号，请重新输入！"){
							SN.alert.info("有重复的用户账号，请重新输入！");
						} else if (response.content == "添加成功！") {//type != 1
							//SN.clearFormValue("MyForm");
							SN.alert.info("添加成功！", function() {
								query();
								closeWindow();
							});
						} else if (response.content == "添加失败！") {
							//SN.clearFormValue("MyForm");
							SN.alert.info("添加失败！", function() {
								query();
								closeWindow();
							});
						}
					} else {
						alert(response.content);
					}
				} ,
				error : function(response, status, statusText) {
					//alert(response + ":" + status + ":" + statusText);
				} ,
				complete : function(response, status, statusText) {
					//alert(response + ":" + status + ":" + statusText);
				}
			});
		}
	}
	function query() {
		parent.query();
	}
	function closeWindow() {
		parent.w1.close();
	}
	//回到顶部按钮添加
	$(document).ready(function () {
            GP.goup({
                trigger: 100,
                bottomOffset: 30,
                locationOffset: 30,
                titleAsText: true,
               containerColor: '#7e7f7e'
            },"Panel_");
    });
		
	$(document).ready(function() {
		$('#MyForm').bootstrapValidator({
			message : 'This value is not valid' ,
			icon : {
				valid : 'glyphicon glyphicon-ok' ,
				invalid : 'glyphicon glyphicon-remove' ,
				validating : 'glyphicon glyphicon-refresh'
			} ,
			fields : {
				"map.staffNumCode" : {
					row : '.col-xs-3' ,
					validators : {
						notEmpty : {
							message : '工号不能为空'
						} ,
						stringLength: {
	                         min: 2,
	                         max: 15,
	                         message: '长度为2-15个字符'
	                     }
					}
				},
				"map.staffName" : {
					row : '.col-xs-3' ,
					validators : {
						notEmpty : {
							message : '员工姓名不能为空'
						} ,
						regexp : {
							regexp : /^([\u4e00-\u9fa5]{1,20}|[a-zA-Z\.\s]{1,20})$/ ,
							message : '长度为1-20的汉字或者1-20英文,.和空格'
						}
					}
				},
				"map.birthday" : {
					row : '.col-xs-3' ,
					validators : {
						notEmpty : {
							message : '员工出生日期不能为空'
						} ,
						regexp : {
							regexp : /^(\d{4})-(0\d{1}|1[0-2])-(0\d{1}|[12]\d{1}|3[01])$/ ,
							message : '请输入正确的时间格式'
						}
					}
				},
				"map.politicalStatus" : {
					row : '.col-xs-3' ,
					validators : {
						regexp : {
							regexp : /^([\u4e00-\u9fa5]){2,10}$/ ,
							message : '长度为2-20的汉字'
						}
					}
				},
				"orgName" : {
					row : '.col-xs-3' ,
					validators : {
						notEmpty : {
							message : '所属部门不能为空'
						} 
					}
				},
				"map.positions" : {
					row : '.col-xs-3' ,
					validators : {
						notEmpty : {
							message : '职位不能为空'
						} ,
						stringLength: {
	                         min: 2,
	                         max: 15,
	                         message: '长度为2-15个字符'
	                     }
					}
				},
				"map.telphone" : {
					row : '.col-xs-3' ,
					validators : {
						notEmpty: {
	                         message: '手机号码不能为空'
	                     },
	                     stringLength: {
	                         min: 11,
	                         max: 11,
	                         message: '请输入11位手机号码'
	                     },
	                     regexp: {
	                         regexp: /^1[3|5|8]{1}[0-9]{9}$/,
	                         message: '请输入正确的手机号码'
	                     }
					}
				},
				"map.telphone1" : {
					row : '.col-xs-3' ,
					validators : {
	                     stringLength: {
	                         min: 11,
	                         max: 11,
	                         message: '请输入11位手机号码'
	                     },
	                     regexp: {
	                         regexp: /^1[3|5|8]{1}[0-9]{9}$/,
	                         message: '请输入正确的手机号码'
	                     }
					}
				},
				"map.email": {
					row : '.col-xs-3' ,
	                 validators: {
	                	 notEmpty: {
	                         message: '电子邮箱不能为空'
	                     },
	                     emailAddress: {
	                         message: '请输入正确的邮件地址如：123@qq.com'
	                     }
	                 }
	             },
	            "map.comment" : {
					row : '.col-xs-9',
					validators : {
						regexp : {
							regexp : /^([^\x00-\xff]|[A-Za-z0-9_\-]){1,50}$/ ,
							message : '长度1-50的汉字，英文，数字，_，-'
						}
					}
				}
			}
		}).on('click', '#birthday', function() {//出生日期
			$('#MyForm').formValidation('addField', 'map.birthday', birthday);
		}).on('success.form.bv', function(e) {
			//alert("验证成功");
			temp = true;
			return temp;
		}).on('error.form.bv', function(e) {
			SN.alert.info("验证失败");
			temp = false;
			return temp;
		});
	});
	$(document).ready(function() {
		var birthday = {
			row : '.col-xs-3' ,
			validators : {
				notEmpty : {
					message : '出生日期不能为空'
				},
				date: {
	                format: 'YYYY-MM-DD',
	               	message : '请输入正确的日期格式YYYY-MM-DD'
	            }
			}
		}
	});
	
	function choiceOrg(){
	/* 	showDivStyle(); */
		$.ajax({
			type : 'POST' ,
			url : 'page/system/org/Org/queryTree' ,
			data :{},
			dataType : "json" ,
			async : true ,
			cache : false ,
			jsonpCallback : "null" ,
			success : function(obj) {
				//alert("initTree=====" + JSON.stringify(obj));
				getTree().deleteChildItems(0);
				getTree().parse(obj.content, "jsarray");
				var m = getTree().getChildItemIdByIndex(0, 0);
				getTree().openItem(m);
			} ,
			error : function(response, status, statusText) {
				//alert(response + ":" + status + ":" + statusText);
			} ,
			complete : function(response, status, statusText) {
				//alert(response + ":" + status + ":" + statusText);
			}
		});
	}
	function initHide() {
		$("#myTree").mouseover(function() {
			$("#myTree").show();
		});
		$("#myTree").mouseout(function() {
			$("#myTree").hide();
		});
	}
	function onSelect(id, name, pid) {
		//alert(id + ":" + name + ":" + pid);
		treeId = id;
		treeName = name;
		$("#orgName").val(treeName);
		$("#orgCode").val(treeId);
	}
	</script>
	<script type="text/javascript">
		function stopFunc(e) {
			e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true;
		}
		$(function($) {
			document.onclick = function(e) {
				//$("#myTree").empty();
				$("#myTree").hide();
			}
			 $("input[name='orgName']").click(function(e) {
				$("#myTree").show();
				choiceOrg();
				e = e || event;
				stopFunc(e);
			}); 
			$("#butTree").click(function(e) {
				$("#myTree").show();
				choiceOrg();
				e = e || event;
				stopFunc(e);
			});
			$("#myTree").click(function(e) {
				e = e || event;
				stopFunc(e);
			}); 
		});
		//文件上传
		function getFile(obj) {//返回上传文件的guid数组
			$("#portraitCode").val(fn_getFileGroupId());
			var fileList = obj["rs_fileList"];
			var fileId = "";
			var count = 0;
			$("#siderImg").empty();
			//$("#siderImg").empty();
			$(fileList).each(function(i, o) {
				fileId = o.id;
				fileName = o.name;
				count++;
				$("#siderImg").append("<img id='photoImage' src='page/common/File/doDownLoad?fileId="+fileId+"' style='width:120px;height:100px;' onclick='imgView($(this))'>");
			});
		}
		//查看大图
		function imgView(_this) {
			var src = $(_this).attr("src");
			imgShow(src);
		}
		//日趋选择插件
		$(function() {
			var startCal = new dhtmlXCalendarObject({
				input : "birthday" ,
				button : "calendar_icon"
			});
			startCal.loadUserLanguage("zh");
		});
	</script>


<body onload="init()">
	<form class="form-horizontal MyForm" id="MyForm" name="MyForm" method="post" target="MyFrame" enctype="multipart/form-data">
		<table class="contTable">
			<tr class="firstTr">
				<td>
					<button onclick="save()" class="btn btn-primary" type="button">
						<span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>&nbsp;<span>保存</span>
					</button>
					<button onclick="closeWindow()" class="btn btn-primary" type="button">
						<span class="glyphicon glyphicon-remove-sign" aria-hidden="true"></span>&nbsp;<span>关闭</span>
					</button>
				</td>
			</tr>
			<tr style="height:auto">
				<td valign="top">
					<div id="Panel_" style="width:100%;height:400px;overflow-y:auto;">
						<div class="blockBorder">
							<div class="titleS">
								<strong>基本信息</strong>
							</div>
							<div class="tableCont" style="width: 90%;">
								<div class="form-group">
									<label class="col-xs-2 control-label" for="staffNumCode">员工工号:</label>
									<div class="col-xs-3 ">
										<input class=" form-control" name="map.staffNumCode" id="staffNumCode" type="" placeholder="" />
									</div>
									<div class="col-xs-1 ">
										<span class="required">*</span>
									</div>
									<label class="col-xs-2 control-label" for="staffName">员工姓名:</label>
									<div class="col-xs-3 ">
										<input class=" form-control" name="map.staffName" id="staffName" type="text" placeholder="" />
									</div>
									<div class="col-xs-1 ">
										<span class="required">*</span>
									</div>
								</div>
								<div class="form-group">
									<label class="col-xs-2 control-label" for="birthday">出生年月:</label>
									<div class="col-xs-3 ">
										<input class="Date form-control" name="map.birthday" id="birthday" type="" placeholder="请选择日期" readonly/>
									</div>
									<div class="col-xs-1 ">
										<span class="required">*</span>
									</div>
									<label class="col-xs-2 control-label" for="politicalStatus">政治面貌:</label>
									<div class="col-xs-3 ">
										<input class=" form-control" name="map.politicalStatus" id="politicalStatus" type="text" placeholder="" />
									</div>
									<div class="col-xs-1 "></div>
								</div>
								<div class="form-group">
									<label class="col-xs-2 control-label" for="email">所属部门:</label>
									<div class="col-xs-3">
										<input class="form-control" type="hidden" name="map.orgCode" id="orgCode" >
										<div class="btn-group right-dropup">
											<input type="text" class="selectInput" name="orgName" id="orgName" style="height:25px;width:82%;" readonly />
											<button id="butTree" type="button" class="btn btn-default dropdown-toggle" style="color:#000000;height:25px" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
												<span class="caret"></span>
											</button>
										</div>
									</div>
									<div class="col-xs-1 ">
										<span class="required">*</span>
									</div>
									<div id="myTree" class="TreeDiv" style="width: 23%;margin-left: 16%; overflow: auto;">
										<jsp:include page="/common/tree.jsp">
											<jsp:param value="getTree" name="getTree" />
											<jsp:param value="false" name="isCheck" />
											<jsp:param value="onSelect" name="onSelect" />
										</jsp:include>
									</div>
									<label class="col-xs-2 control-label" for="positions">职务:</label>
									<div class="col-xs-3">
										<input class="form-control" name="map.positions" id="positions" type="text" placeholder="" />
									</div>
									<div class="col-xs-1 ">
										<span class="required">*</span>
									</div>
								</div>
								<div class="form-group">
									<label class="col-xs-2 control-label" for="telphone">手机号码1:</label>
									<div class="col-xs-3">
										<input class="form-control" name="map.telphone" id="telphone" type="text" placeholder="" />
									</div>
									<div class="col-xs-1 ">
										<span class="required">*</span>
									</div>
									<label class="col-xs-2 control-label" for="telphone1">手机号码2:</label>
									<div class="col-xs-3">
										<input class="form-control" name="map.telphone1" id="telphone1" type="text" placeholder="" />
									</div>
									<div class="col-xs-1 "></div>
								</div>
								<div class="form-group">
									<label class="col-xs-2 control-label" for="email">电子邮箱:</label>
									<div class="col-xs-3">
										<input class="form-control" name="map.email" id="email" type="text" placeholder="" />
									</div>
									<div class="col-xs-1 ">
										<span class="required">*</span>
									</div>
								</div>
								<div class="form-group">
									<label class="col-xs-2 control-label" for="portraitCode">照片:</label>
									<div class="col-xs-9">
										<jsp:include page="/common/FileUpload_Toolbar.jsp">
											<jsp:param name="accept" value="applicationmn" />
											<jsp:param name="fn_getFile" value="getFile" />
											<jsp:param name="fn_setFileGroupId" value="fn_setFileGroupId" />
											<jsp:param name="fn_getFileGroupId" value="fn_getFileGroupId" />
										</jsp:include>
										<input class="form-control" name="map.portraitCode" id="portraitCode" type="hidden" placeholder="" />
										<div id="siderImg" style="margin-top:5px;">
											<ul></ul>
										</div>
									</div>
									<jsp:include page="/WEB-INF/page/common/File_ViewBigPic.jsp">
										<jsp:param name="imgShow" value="imgShow" />
									</jsp:include>
									<div class="col-xs-1"></div>
								</div>
								<div class="form-group">
									<label class="col-xs-2 control-label" for="comment">备注:</label>
									<div class="col-xs-9">
										<textarea style=" resize: none;" class="form-control" name="map.comment" id="comment" type="text" placeholder="" rows="3" cols=""></textarea>
									</div>
									<div class="col-xs-1 "></div>
								</div>
							</div>
						</div>
						
					</div>
				</td>
			</tr>
		</table>
	</form>
</body>
</html>
